package com.ysy.tz.core.selfcomp;

import com.ysy.tz.core.engine.KeyValuePair;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.ComboBox;
import javafx.util.StringConverter;

public class CustomerComboBox extends ComboBox<KeyValuePair> {
    private Map<String, Object> keyValueMap;

    public CustomerComboBox() {
        this(FXCollections.observableArrayList());
    }

    public CustomerComboBox(ObservableList<KeyValuePair> items) {
        super(items);
        this.keyValueMap = new HashMap();
        this.itemsProperty().addListener(new ChangeListener<ObservableList<KeyValuePair>>() {
            public void changed(ObservableValue<? extends ObservableList<KeyValuePair>> observable, ObservableList<KeyValuePair> oldValue, ObservableList<KeyValuePair> newValue) {
                CustomerComboBox.this.keyValueMap.clear();
                Iterator var4 = newValue.iterator();

                while(var4.hasNext()) {
                    KeyValuePair keyValuePair = (KeyValuePair)var4.next();

                    String strValue;
                    for(strValue = keyValuePair.getValuePair(); CustomerComboBox.this.keyValueMap.get(strValue) != null; strValue = strValue + " ") {
                    }

                    CustomerComboBox.this.keyValueMap.put(strValue, keyValuePair);
                }

            }
        });
        this.setConverter(new KeyValueConvertor());
    }

    class KeyValueConvertor extends StringConverter {
        KeyValueConvertor() {
        }

        public String toString(Object object) {
            Iterator var2 = CustomerComboBox.this.keyValueMap.entrySet().iterator();

            Map.Entry entry;
            do {
                if (!var2.hasNext()) {
                    return null;
                }

                entry = (Map.Entry)var2.next();
            } while(entry.getValue() != object);

            return (String)entry.getKey();
        }

        public Object fromString(String string) {
            return CustomerComboBox.this.keyValueMap.get(string);
        }
    }
}
